package stark.app.function.wifi;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;

import androidx.annotation.NonNull;
import stark.app.R;
import stark.app.databinding.DialogWifiPwdBinding;
import stark.common.basic.base.BaseSmartDialog;

/**
 * Author：daizhongbin on 2022/5/5
 * Email：1027154338@qq.com
 * Desc:
 */
public class WifiPwdDialog extends BaseSmartDialog<DialogWifiPwdBinding> {

    public WifiPwdDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_wifi_pwd;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.btnConfirm.setOnClickListener(v -> {
            String pwd = mDataBinding.etPwd.getText().toString().trim();
            if (TextUtils.isEmpty(pwd)) {
                mDataBinding.etPwd.requestFocus();
                ToastUtils.showShort("请输入Wifi密码");
                return;
            }
            if (listener != null) {
                listener.onConnect(pwd);
            }
            dismiss();
        });
    }

    private IListener listener;

    public void setListener(IListener listener) {
        this.listener = listener;
    }

    public interface IListener {

        void onConnect(@NonNull String password);

    }
}
